<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0px;padding: 0px;}
        #oDiv1{background-color: red;width: 100px;height: 100px;position: absolute;}
    </style>
    <script>
        window.onload = function(){
            var oDiv = document.getElementById("oDiv1")

            drag(oDiv)
        }
        // window.onload = function(){
            function drag(node){
                    

                    node.onmousedown = function(ev){
                    var e = ev || window.event
                    var offsetX = e.clientX - node.offsetLeft;
                    var offsetY = e.clientY - node.offsetTop;

                    document.onmousemove = function(ev){
                        var e = ev || window.event
                        node.style.left = e.clientX - offsetX + 'px'
                        node.style.top = e.clientY - offsetY+ 'px'
                    } 
                    
                }
               document.onmouseup = function(){
                    document.onmousemove = null
                }
            }
            
        // }
    </script>
</head>
<body>
    <div id = 'oDiv1'>
        
    </div>
</body>
</html>